<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/view/include/taglib.jsp"%>
<html>
<head>
	<title>${dict:getConfigValueByKey('WEB_NAME','管理平台')} | 任务调度</title>
	<meta name="description" content="app, web app, responsive, admin dashboard, admin, flat, flat ui, ui kit, off screen nav" />
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
	<link rel="icon" type="image/png" href="icon.png">
	<link rel="apple-touch-icon-precomposed" href="icon.png">
	<link rel="stylesheet" href="${ctxStatic}/js/jPlayer/jplayer.flat.css" type="text/css" />
	<link rel="stylesheet" href="${ctxStatic}/css/bootstrap.css" type="text/css" />
	<link rel="stylesheet" href="${ctxStatic}/css/animate.css" type="text/css" />
	<link rel="stylesheet" href="${ctxStatic}/css/font-awesome.min.css" type="text/css" />
	<link rel="stylesheet" href="${ctxStatic}/css/simple-line-icons.css" type="text/css" />
	<link rel="stylesheet" href="${ctxStatic}/css/font.css" type="text/css" />
	<link rel="stylesheet" href="${ctxStatic}/css/app.css" type="text/css" />
	<link rel="stylesheet" href="${ctxStatic}/js/ztree/css/zTreeStyle.css">
	<%--<link rel="stylesheet" href="${ctxStatic}/js/page/paging.css" type="text/css" />--%>
	<!--[if lt IE 9]>
	<script src="${ctxStatic}/js/ie/html5shiv.js"></script>
	<script src="${ctxStatic}/js/ie/respond.min.js"></script>
	<script src="${ctxStatic}/js/ie/excanvas.js"></script>
	<![endif]-->
</head>
<body>
<section class="scrollable wrapper">
	<div class="row">
		<div class="col-lg-12">
			<!-- 引导开始 -->
			<ul class="breadcrumb">
				<li><a href="${ctx}/welcome"><i class="fa fa-home"></i> 主页</a></li>
				<li>系统设置</li>
				<li class="active">任务调度管理</li>
			</ul>
			<!-- 引导结束 -->
		</div>
	</div>

	<section class="panel panel-default">
		<%--操作区域 开始--%>
		<div class="row wrapper">
			<div class="col-sm-5 m-b-xs">
				<button class="btn btn-sm btn-default" onclick="openModel(false,'${ctx}/scheduleJob/update')">新增</button>
			</div>
			<div class="col-sm-4 m-b-xs">
				<label class="btn btn-sm btn-default active">系统核心功能</label>
				<%--<div class="btn-group" data-toggle="buttons">--%>
				<%--<label class="btn btn-sm btn-default active">--%>
				<%--<input type="radio" name="options"> 每天--%>
				<%--</label>--%>

				<%--<label class="btn btn-sm btn-default">--%>
				<%--<input type="radio" name="options"> 每周--%>
				<%--</label>--%>

				<%--<label class="btn btn-sm btn-default">--%>
				<%--<input type="radio" name="options"> 每月--%>
				<%--</label>--%>
				<%--</div>--%>
			</div>
			<%--搜索区域--%>
			<div class="col-sm-3">
				<div class="input-group">
					<input id="searchKey" type="text" class="input-sm form-control" placeholder="输入关键词">
					<span class="input-group-btn">
                            <button onclick="searchPage(1);" class="btn btn-sm btn-default" type="button">搜索</button>
                    </span>
				</div>
			</div>
		</div>
		<%--操作区域 结束--%>

		<div class="table-responsive">
			<table class="table table-striped b-t b-light">
				<thead>
				<tr>
					<%--<th class="text-center" ><label class="checkbox m-n i-checks"><input type="checkbox"><i></i></label></th>--%>
					<th class="text-center" >序号</th>
					<th class="text-center" >名称</th>
					<th class="text-center" >分组</th>
					<th class="text-center" >表达式</th>
					<th class="text-center" >状态</th>
					<th class="text-center" >执行方法</th>
					<%--<th class="text-center" width="10%">修改时间</th>--%>
					<th class="text-center">描述</th>
					<th class="text-center" width="">操作</th>
				</tr>
				</thead>
				<tbody id="tplView">

				</tbody>
			</table>
		</div>

		<footer class="panel-footer">
			<div class="row">
				<%--分页--%>
				<div id="page" class="col-sm-12 text-right text-center-xs"></div>
			</div>
		</footer>

	</section>

</section>
</body>
<script src="${ctxStatic}/js/jquery.min.js"></script>
<!-- Bootstrap -->
<script src="${ctxStatic}/js/bootstrap.js"></script>
<!-- App -->
<script src="${ctxStatic}/js/app.js"></script>
<script src="${ctxStatic}/js/slimscroll/jquery.slimscroll.min.js"></script>
<script src="${ctxStatic}/js/app.plugin.js"></script>
<script type="text/javascript" src="${ctxStatic}/js/jPlayer/jquery.jplayer.min.js"></script>
<script type="text/javascript" src="${ctxStatic}/js/jPlayer/add-on/jplayer.playlist.min.js"></script>
<script type="text/javascript" src="${ctxStatic}/js/jPlayer/demo.js"></script>
<script type="text/javascript" src="${ctxStatic}/js/tools.js?version=${ctxVersion}"></script>
<script type="text/javascript" src="${ctxStatic}/js/page/paging.js?12321222222321233232"></script>
<script type="text/javascript" src="${ctxStatic}/js/layer/layer.js"></script>
<script type="text/javascript" src="${ctxStatic}/js/tmpl/jquery.tmpl.js"></script>
<script type="text/javascript" src="${ctxStatic}/js/table2excel/jquery.table2excel.js"></script>
<script id="tplHtml" type="text/x-jquery-tmpl">
    {{if results && results.length>0}}
        {{each results}}
        <tr>
            <%--<td class="text-center" ><label class="checkbox m-n i-checks"><input type="checkbox" name="post[]"><i></i></label></td>--%>
            <td class="text-center" >{{= ($index+1)+(pageNo-1)*10}}</td>
            <td>{{= jobName }}</td>
            <td class="text-center" >{{= jobGroup }}</td>
            <td>{{= cron }}</td>
            <td class="text-center">{{if status=='1'}}<span class="label label-success">启用</span>{{else}}<span class="label label-danger">停用</span>{{/if}}</td>
            <td class="text-center">{{= methodName }}</td>
            <%--<td>{{= updateDateStr }}</td>--%>
            <td>{{= remarks }}</td>
            <td class="text-center" >
				{{if status =='2'}}
					<a href="javascript:resumeJob('{{= id }}','1');" class="btn btn-default btn-xs">恢复</a>
				{{/if}}
				{{if status =='1'}}
					<a href="javascript:runAJobNow('{{= id }}');" class="btn btn-success btn-xs">执行</a>
					<a href="javascript:pauseJob('{{= id }}','2');" class="btn btn-warning btn-xs">暂停</span></a>
					<a href="javascript:changeJobStatus('{{= id }}','0');" class="btn btn-danger btn-xs">停止</span></a>
				{{/if}}
				{{if status =='0'}}
					<a href="javascript:changeJobStatus('{{= id }}','1');" class="btn btn-success btn-xs">启用</span></a>
					<a href="javascript:;" onclick="openModel(false,'${ctx}/scheduleJob/update?id={{= id}}')" class="btn btn-primary btn-xs">修改</a>
				{{/if}}
			</td>
        </tr>
        {{/each}}
    {{else}}
        <tr><td colspan="6" class="text-center">暂无数据</td></tr>
    {{/if}}
</script>
<script>
    $(function(){
        searchPage(1);
    })
    //查询分页数据
    function searchPage(num){
        var jobName = $("#searchKey").val();
        var loadingLayer = layer.load(1, {shade: [0.1,'#fff']});//loading
        $.ajax({
            type: 'post',
            url: '${ctx}/scheduleJob/list.json?timeStamp='+new Date().getTime(),
            dataType:"json",
            data: {"pageNo":num,"pageSize":$("#paging_js_page_size").val(),"jobName":jobName},
            success: function (data) {
                var page = data.data;
                layer.close(loadingLayer);
                $( "#tplView" ).empty();
                $( "#tplHtml" ).tmpl( data.data ).appendTo( "#tplView" );

                //分页
                $("#page").paging({
                    pageNo:page.pageNo,
                    totalPage: page.totalPage,
                    totalSize: page.totalRecord,
                    callback: function(num) {
                        searchPage(num);
                    }
                })

            },error:function(){
                   layer.close(loadingLayer);
                   showMsg("点击过快或程序异常");
                }
        });
    }

    /** 恢复任务 */
    function resumeJob(id,status){
        layer.confirm('确认恢复该任务吗？<br/><span class="text-danger">(注：系统核心数据，谨慎操作)</span>', {
            btn: ['确认恢复任务','取消'] //按钮
        }, function(){
            var loadingLayer = layer.load(1, {shade: [0.1,'#fff']});//loading
            $.ajax({
                type: 'post',
                url: '${ctx}/scheduleJob/resumeJob.json?timeStamp='+new Date().getTime(),
                dataType:"json",
                data: {"status":status,"id":id},
                success: function (data) {
                    layer.close(loadingLayer);
                    showMsg(data.desc);
                    searchPage(1);
                },error:function(){
                    layer.close(loadingLayer);
                    showMsg("点击过快或程序异常");
                }
            });
        }, function(){

        });
	}

	/** 立即执行 */
	function runAJobNow(id){
        layer.confirm('确认立即执行该任务吗？<br/><span class="text-danger">(注：系统核心数据，谨慎操作)</span>', {
            btn: ['确认执行','取消'] //按钮
        }, function(){
            var loadingLayer = layer.load(1, {shade: [0.1,'#fff']});//loading
            $.ajax({
                type: 'post',
                url: '${ctx}/scheduleJob/runAJobNow.json?timeStamp='+new Date().getTime(),
                dataType:"json",
                data: {"id":id},
                success: function (data) {
                    layer.close(loadingLayer);
                    showMsg(data.desc);
                    searchPage(1);
                },error:function(){
                    layer.close(loadingLayer);
                    showMsg("点击过快或程序异常");
                }
            });
        }, function(){

        });
	}


    /** 暂停任务 */
    function pauseJob(id,status){
        layer.confirm('确认暂停该任务吗？<br/><span class="text-danger">(注：系统核心数据，谨慎操作)</span>', {
            btn: ['确认暂停任务','取消'] //按钮
        }, function(){
            var loadingLayer = layer.load(1, {shade: [0.1,'#fff']});//loading
            $.ajax({
                type: 'post',
                url: '${ctx}/scheduleJob/pauseJob.json?timeStamp='+new Date().getTime(),
                dataType:"json",
                data: {"status":status,"id":id},
                success: function (data) {
                    layer.close(loadingLayer);
                    showMsg(data.desc);
                    searchPage(1);
                },error:function(){
                    layer.close(loadingLayer);
                    showMsg("点击过快或程序异常");
                }
            });
        }, function(){

        });
    }

    /** 启动、停止任务 */
    function changeJobStatus(id,status){
        var titleType = "";
        if("0"==status){//停止
            titleType = "停止";
        }else if("1"==status){//启动
            titleType = "启动";
        }else{
            showMsg("参数不正确");
            return false;
        }
        layer.confirm('确认'+titleType+'该任务吗？<br/><span class="text-danger">(注：系统核心数据，谨慎操作)</span>', {
            btn: ['确认'+titleType+'任务','取消'] //按钮
        }, function(){
            var loadingLayer = layer.load(1, {shade: [0.1,'#fff']});//loading
            $.ajax({
                type: 'post',
                url: '${ctx}/scheduleJob/changeJobStatus.json?timeStamp='+new Date().getTime(),
                dataType:"json",
                data: {"status":status,"id":id},
                success: function (data) {
                    layer.close(loadingLayer);
                    showMsg(data.desc);
                    searchPage(1);
                },error:function(){
                    layer.close(loadingLayer);
                    showMsg("点击过快或程序异常");
                }
            });
        }, function(){

        });
    }
</script>
</html>
